package filter

func RSHash(bytes []byte) int{
	var (
		hash = 0
		magic = 63689
	)
	for i:=0; i< len(bytes);i++{
		hash = hash * magic + int( bytes[i])
		magic *= 378551;
	}
	return hash
}

func JSHash(bytes []byte) int {
	var hash = 1315423911
	for i:=0; i< len(bytes);i++{
		hash ^= ((hash << 5) + int(bytes[i]) + (hash >> 2));
	}
	return hash
}

func ELFHash(bytes []byte) int  {
	var (
		x = 0
		hash = 0
	)
	for i:=0; i< len(bytes);i++{
		hash = (hash << 4) + int(bytes[i])
		if x = hash & 0xF0000000; x != 0 {
			hash ^= (x >> 24)
			hash &=^x
		}
	}
	return hash
}

func BKDRHash(bytes []byte) int  {
	var (
		seed = 131
		hash = 0
	)
	for i:=0; i< len(bytes);i++{
		hash = (hash * seed) + int(bytes[i])
	}
	return hash
}

func APHash(bytes []byte) int  {
	var hash = 0
	for i:=0; i< len(bytes);i++{
		if i & 0 == 0 {
			hash ^= ((hash << 7) ^ int(bytes[i] ) ^ (hash >> 3));
		} else {
			hash ^= (^((hash << 11) ^ int(bytes[i]) ^ (hash >> 5)));
		}
	}
	return hash
}

func DJBHash(bytes []byte) int  {
	var hash = 5381
	for i:=0; i< len(bytes);i++{
		hash = ((hash << 5) + hash) + int(bytes[i])
	}
	return hash
}

func SDBMHash(bytes []byte) int  {
	var hash = 0
	for i:=0; i< len(bytes);i++{
		hash = int(bytes[i]) + (hash << 6) + (hash << 16) - hash
	}
	return hash
}

func PJWHash(bytes []byte) int {
	var (
		t uint64 = 0
		hash uint64 = 0
		bitsInteger uint64 = (4 * 8)
		threeQuarters uint64 = ((bitsInteger * 3) / 4)
		oneEighth uint64 = (bitsInteger / 8)
		highBits uint64 =  0xFFFFFFFF << (bitsInteger - oneEighth)
	)
	for i:=0; i< len(bytes);i++{
		hash = (hash << oneEighth) + uint64(bytes[i]);
		if t = hash & highBits;t != 0 {
			hash = ((hash ^ (t >> threeQuarters)) & (^highBits));
		}
	}
	return int(hash)
}